﻿@using System.Collections
@model IEnumerable<MMSWebsite.Models.Customer>
@{ string controller = this.Url.RouteUrl(this.ViewContext.RouteData.Values); //get UrL = "/controller/action")
    string nameView = ViewBag.NameView; //get name SearchForm from ViewBag in code behind
}

<table>
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.CompanyNm)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Code)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Name)
        </th>
        @*<th>
            @Html.DisplayNameFor(model => model.IdCode)
        </th>*@
        <th>
            @Html.DisplayName("Address")
        </th>
        @*<th>
            @Html.DisplayNameFor(model => model.Email)
        </th>*@
        <th>
            @Html.DisplayNameFor(model => model.Phone)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.ResponsibleEmp)
        </th>
         <th>
            @Html.DisplayName("Est Start")
        </th>
        <th>
            @Html.DisplayName("Est End")
        </th>
         @if (!nameView.Equals("Allocation"))
         {
             <th>
                @Html.DisplayName("Finished")
             </th>
         }
        <th>
            @if(nameView == "StoreResult")
            {
                @: @Html.DisplayName("Result")
            }
        </th>
    </tr>
    
    @{
        //paramater to use for color row in table show
        var OddColor = "#DDEEEE";
        var evenColor = "#EEFFFF";
        var Odd = OddColor;
        int i = 0;
    }
@foreach (var item in Model)
{
    //Check Customer has FV or not, if not -> value columns Responsibility = Empty 
    var valueResEmp = string.Empty; 
    if (item.ResponsibleEmp != null)
    {
        valueResEmp = item.ResponsibleEmp.Employee.Name;//valueResEmp is used to set default value for Dropdownlist Responsibility
    }
    //----------------------------------------------------------------------------
    
    <tr bgcolor="@Odd">
        <td>
            @Html.DisplayFor(modelItem => item.CompanyNm)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Code)
        </td>
        <td>
            @if (nameView == "Processing")
            {
                @Html.DisplayFor(modelItem => item.Name)
            }
            else
            {
                <a href="@Url.Action("Details", "CusMgn", new {id = @item.Id})" style=" color: darkCyan; font-weight: bold">@Html.DisplayFor(modelItem => item.Name)</a>
            }
        </td>
        @*<td>
            @Html.DisplayFor(modelItem => item.IdCode)
        </td>*@
        <td>
            @Html.DisplayFor(modelItem => item.NumberAddress) , 
            @Html.DisplayFor(modelItem => item.Area.DistrictName) , 
            @Html.DisplayFor(modelItem => item.Area.CityName)
        </td>
       @* <td>
            @Html.DisplayFor(modelItem => item.Email)
        </td>*@
        <td>
            @Html.DisplayFor(modelItem => item.Phone)
        </td>
        <td style=" color: darkCyan; font-weight: bold">
            @*check current page is Allocation or Processing*@
            @if (!nameView.Equals("Allocation"))// check current page is processing
            {
                @item.ResponsibleEmp.Employee.Name
            }
            else //current page is allocation
            {
                <input type="hidden" name="List[@i].Id" value='@item.Id' />
                @Html.DropDownList("List[" + @i + "].ResponsibleEmp.Employee.Name",
                                   new SelectList(ViewBag.Emps as IEnumerable),
                                   @valueResEmp,
                                   new { style = "text-align: center; color: darkCyan; font-weight:bold; width:200px " })
            }
        </td>
        @if (nameView.Equals("Allocation"))
        {
            <td><input type="date" name = "List[@i].StartDay"></td>
            <td><input type="date" name = "List[@i].EndDay"></td>
        }
        else
        {
            <td style="text-align: center">@item.StartDay.Value.ToShortDateString()</td>
            <td style="text-align: center">@item.EndDay.Value.ToShortDateString()</td>
            <td style="text-align: center">
                @if (item.FinishedDay != null)
                {
                    @: @item.FinishedDay.Value.ToShortDateString()
                }
                else
                {
                    @: @item.FinishedDay
                }
            </td>
        }
        <td>
            @if (nameView == "Processing") //Show icon user-delete if current page is processing
            {
            <a href="@Url.Action("RemoveResponsibility", "CusMgn", new { cusId = item.Id })">
                <img alt="Remove Responsibility" src="~/Images/business_user_delete.png" width="50px" height="50px" style="text-align: right">
            </a>
            }
            @if(nameView == "StoreResult")
            {
                @: @item.Status.value
            }
        </td>

    </tr>
    i++;
    Odd = Odd == OddColor ? evenColor : OddColor;
}

</table>
